/**
 * Created By zhangQ 2018/2/12
 * 路由配置
 */
import frontEnd from '@views/frontEnd/main'
import userModule from '@views/userModule/main'
import backEnd from '@views/backEnd/main'
import lightStation from '@views/lightStation/main'
import containerPlatform from '@views/containerPlatform/main'
import stationReport from '@views/stationReport/main'
import xlinkConf from '@views/xlinkConf/index.vue'

let constantRouterMap = []
// 路由是否验证,默认验证
let routerConfig = {
  required: true
}

/**
 * TODO(递归生产路由)
 * @param router:::路由
 * @auther zhangQ
 * @date 2018/2/14 9:52
 **/
function routerFactorial (router, routerMap) {
  for (let i = 0, leni = router.length; i < leni; i++) {
    let routerItem = router[i]
    let defalutRouter = {
      name: '',
      path: '/',
      component: '',
      hidden: true,
      meta: { required: routerConfig.required }
    }
    if (routerItem.meta) {
      routerItem.meta = Object.assign(defalutRouter.meta, routerItem.meta)
    }
    let resRouter = Object.assign({}, defalutRouter, routerItem)
    if (resRouter.children && resRouter.children.length > 0) {
      let resChildren = []
      routerFactorial(resRouter.children, resChildren)
      resRouter.children = resChildren
    }
    routerMap.push(resRouter)
  }
}

routerFactorial(frontEnd, constantRouterMap)
routerFactorial(userModule, constantRouterMap)
routerFactorial(backEnd, constantRouterMap)
routerFactorial(lightStation, constantRouterMap)
routerFactorial(containerPlatform, constantRouterMap)
routerFactorial(stationReport, constantRouterMap)

let debug = process.env.NODE_ENV !== 'production'
if (debug) {
  constantRouterMap.push({
    path: '/xlink_conf',
    name: 'xlinkConf',
    component: xlinkConf
  })
  console.log('配置路由表：', constantRouterMap)
}
export default constantRouterMap
